package Interfaz;
import java.util.Vector;

public class ListaTagsGui extends javax.swing.JDialog {

    Vector tags = new Vector();
    
    public ListaTagsGui(java.awt.Frame parent, boolean modal, Vector tag) {
        super(parent, modal);
        initComponents();
        tags=tag;
        jListaTags.setListData(tags);
    }
    
    public ListaTagsGui(javax.swing.JDialog parent, boolean modal, Vector tag) {
        super(parent, modal);
        initComponents();
        tags=tag;
        jListaTags.setListData(tags);
    }
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jScrollPane1 = new javax.swing.JScrollPane();
        jListaTags = new javax.swing.JList();
        jBtnEliminar = new javax.swing.JButton();
        jBtnSubir = new javax.swing.JButton();
        jBtnBajar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Lista de Tags");
        setAlwaysOnTop(true);
        setModal(true);
        jScrollPane1.setViewportView(jListaTags);

        jBtnEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/list-remove.png")));
        jBtnEliminar.setText("Remove selected");
        jBtnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnEliminarActionPerformed(evt);
            }
        });

        jBtnSubir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/go-up.png")));
        jBtnSubir.setText("Move up");
        jBtnSubir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnSubirActionPerformed(evt);
            }
        });

        jBtnBajar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/go-down.png")));
        jBtnBajar.setText("Move down");
        jBtnBajar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnBajarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jBtnBajar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jBtnSubir, javax.swing.GroupLayout.DEFAULT_SIZE, 114, Short.MAX_VALUE)
                    .addComponent(jBtnEliminar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jBtnSubir)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBtnBajar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 60, Short.MAX_VALUE)
                .addComponent(jBtnEliminar)
                .addContainerGap())
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBtnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnEliminarActionPerformed
        tags.removeElementAt(jListaTags.getSelectedIndex());
        jListaTags.setListData(tags);
    }//GEN-LAST:event_jBtnEliminarActionPerformed

    private void jBtnBajarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnBajarActionPerformed
        try{
            String t1 = (String) tags.get(jListaTags.getSelectedIndex());
            String t2 = (String) tags.get(jListaTags.getSelectedIndex()+1);

            tags.setElementAt(t2, jListaTags.getSelectedIndex());
            tags.setElementAt(t1, jListaTags.getSelectedIndex()+1);
            int nuevoIndex = jListaTags.getSelectedIndex() + 1; 
                    

            jListaTags.removeAll();
            jListaTags.setListData(tags);
            jListaTags.setSelectedIndex(nuevoIndex);
        }catch(Exception e){}
    }//GEN-LAST:event_jBtnBajarActionPerformed

    private void jBtnSubirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnSubirActionPerformed
        try{
            String t1 = (String) tags.get(jListaTags.getSelectedIndex());
            String t2 = (String) tags.get(jListaTags.getSelectedIndex()-1);
            
            int nuevoIndex = jListaTags.getSelectedIndex() - 1;
            
            tags.setElementAt(t2, jListaTags.getSelectedIndex());
            tags.setElementAt(t1, jListaTags.getSelectedIndex()-1);

            jListaTags.removeAll();
            jListaTags.setListData(tags);
            jListaTags.setSelectedIndex(nuevoIndex);
        }catch(Exception e){}
    }//GEN-LAST:event_jBtnSubirActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBtnBajar;
    private javax.swing.JButton jBtnEliminar;
    private javax.swing.JButton jBtnSubir;
    private javax.swing.JList jListaTags;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
    
}
